"""
院区模型
创建时间：2025-09-12
作者：开发团队
目的：定义院区数据模型
"""

from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from ..core.database import Base


class Campus(Base):
    """院区模型"""
    
    __tablename__ = "campuses"
    
    # 基础字段
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    name = Column(String(100), unique=True, nullable=False)
    address = Column(String(200))
    contact_person = Column(String(50))
    contact_phone = Column(String(20))
    created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), nullable=False)
    updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc), nullable=False)
    
    # 关系
    users = relationship("User", back_populates="campus")
    special_visitors = relationship("SpecialVisitor", back_populates="campus")
    
    def __repr__(self):
        return f"<Campus(id={self.id}, name='{self.name}')>"